package com.woniu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.been.entity.News;
import com.woniu.been.entity.vo.NewsVo;
import com.woniu.mapper.NewsMapper;
import com.woniu.service.NewsService;
import com.woniu.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsMapper newsMapper;

    @Override
    public PageResult findAllNews(NewsVo newsVo, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<NewsVo> sysNewsList = newsMapper.findAllNews(newsVo);
        PageInfo<NewsVo> pageInfo = new PageInfo<>(sysNewsList);
        PageResult ps = new PageResult(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal(), pageInfo.getList());
        return ps;
    }

    @Override
    public void deleteNews(Integer id) {
        newsMapper.deleteNews(id);
    }

    @Override
    public List<String> queryOperNameList() {
        return newsMapper.queryOperNameList();
    }

    @Override
    public void insertNews(News news) {
        newsMapper.insertNews(news);
    }

    @Override
    public void updateNewsById(News news) {
        newsMapper.updateNewsById(news);
    }

    @Override
    public News findNewsById(Integer id) {
        return newsMapper.findNewsById(id);
    }

}
